#include "Surface.h"

SDL_Surface *Surface::load_image(char *file)
{
    SDL_Surface *tmp, *ret;
    if((tmp = IMG_Load(file)) == NULL) return NULL;
    if((ret = SDL_DisplayFormatAlpha(tmp)) == NULL) return NULL;
    SDL_FreeSurface(tmp);
    return ret;
}

void Surface::apply_surface(SDL_Surface *source, SDL_Surface *destination, int dX, int dY)
{
    if(source == NULL || destination == NULL) return;
    
    SDL_Rect dRect;
    dRect.x = dX;
    dRect.y = dY;
    
    SDL_BlitSurface(source, NULL, destination, &dRect);
}

void Surface::apply_surface(SDL_Surface *source, int sX, int sY, int sW, int sH, SDL_Surface *destination, int dX, int dY)
{
    if(source == NULL || destination == NULL) return;
    
    SDL_Rect sRect = {sX,sY,sW,sH};
    SDL_Rect dRect = {dX,dY};
    
    SDL_BlitSurface(source, &sRect, destination, &dRect);
}


void Surface::transparent(SDL_Surface *destination, int r, int g, int b)
{
        if(destination == NULL) return;
        SDL_SetColorKey(destination, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(destination->format, r, g , b));
}
